package com.childmiles.service.persistence;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.childmiles.gwt.client.domain.AwardWinner;

/**
 * 
 * Hold objects in memory until we build persistence layer
 */
public class QuickAndDirtyDaoImpl implements Dao {

	private static Map<String, AwardWinner> awardWinnersByName = new HashMap<String, AwardWinner>();

	/**
	 * save in a static map (which gets wiped away on appengine when it's swapped out)
	 */
	public void save(AwardWinner awardWinner) {
		awardWinnersByName.put(awardWinner.getName().toLowerCase(), awardWinner);
	}

	/* (non-Javadoc)
	 * @see com.childmiles.service.Dao#find(java.lang.String)
	 */
	public AwardWinner find(String name) {
		return awardWinnersByName.get(name.toLowerCase());
	}

    public List<AwardWinner> findAll() {
        return new ArrayList<AwardWinner>(awardWinnersByName.values());
    }
}
